package ee.ut.maxorato_macobo.oop.mud.items;

import java.util.Iterator;
import java.util.Map.Entry;
import java.util.TreeMap;

public class ItemLoaderPool {
	private static TreeMap<Long, ItemLoader> loaderList = new TreeMap<Long, ItemLoader>();
	
	public static boolean registerLoader(ItemLoader loader) {
		if(loaderList.containsKey(loader.getIndex())) return false;
		
		loaderList.put(loader.getIndex(), loader);
		return true;
	}
	
	public static boolean unregisterLoader(ItemLoader loader) {
		if(!loaderList.containsKey(loader.getIndex())) return false;
		
		loaderList.remove(loader.getIndex());
		return true;
	}
	
	public static void processTick() {
		Iterator<Entry<Long, ItemLoader>> it = loaderList.entrySet().iterator();
		
		while(it.hasNext()) {
			Entry<Long, ItemLoader> entry = it.next();
			
			entry.getValue().processRepopping();
		}
	}
	
	public static TreeMap<Long, ItemLoader> getLoaderList() {
		return loaderList;
	}
	
	private ItemLoaderPool() {
		
	}
}
